<template>
    <view class="content">
        <view class="nav">
            <scroll-view scroll-x>
                <view class="nav-i">
                    <view class="nav-i2" :class="{isNav : item.id == cateId}" 
                        v-for="(item, index) in cate" :key="index" @click="change(item)">
                        {{item.name}}
                    </view>
                </view>
            </scroll-view>
        </view>
        <view class="b-item" v-for="(item, index) in list" :key="index" @click="$gTo('/pages/activity/details?id=' + item.id)">
            <image :src="item.image" class="b-img"></image>
            <view class="b-item-right">
                <view class="b-name">{{item.title}}</view>
                <view class="b-time">
                    <image src="../../static/icon/time_03.png" class="time-04"></image>
                    已结束
                </view>
            </view>
            <image src="../../static/icon/arrow_r.png" class="arrow-r"></image>
        </view>
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                cate: [],
                cateId: '',
            };
        },
        onLoad() {
            this.getCate()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            change(item) {
                if (this.cateId == item.id) return
                this.cateId = item.id
                this.page = 1
                this.list = []
                this.status = 'loadmore'
                this.getList()
            },
            
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('activity_list', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    status: 2,//1进行中活动 2往期活动
                    type: this.cateId,//类型
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.activity && ret.detail.activity.length > 0) {
            				this.list = this.list.concat(ret.detail.activity);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
            
            // 获取活动分类
            getCate() {
            	this.$ajax('activity_type', {
                    
            	}).then(ret => {
            		if (ret.success == 1000) {
                        this.cate = ret.detail.activity_type
                        if (this.cate && this.cate[0]) {
                            this.cateId = this.cate[0].id
                            this.getList()
                        }
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #ffffff;
    }
    .content{
        padding: 30rpx;
    }
    .nav{
        width: 690rpx;
        white-space: nowrap;
        padding-bottom: 20rpx;
    }
    .nav-i{
        display: flex;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
    }
    .nav-i2{
        background-color: #efefef;
        font-size: 26rpx;
        line-height: 1;
        color: #a5a5a5;
        margin-right: 20rpx;
        padding: 18rpx 65rpx;
    }
    .isNav{
        color: #fff;
        background-color: #40bef1;
    }
    .b-item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #efefef;
        padding: 20rpx;
        border-radius: 20rpx;
        margin-bottom: 20rpx;
    }
    .b-img{
        width: 111rpx;
        height: 111rpx;
        border-radius: 10rpx;
        margin-right: 20rpx;
    }
    .b-item-right{
        flex: 1;
    }
    .b-name{
        width: 460rpx;
        font-size: 28rpx;
        font-weight: bold;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-bottom: 10rpx;
    }
    .b-time{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        font-size: 22rpx;
        color: #7d7d7d;
    }
    .time-04{
        width: 18rpx;
        height: 18rpx;
        margin-right: 6rpx;
    }
    .arrow-r{
        width: 26rpx;
        height: 8rpx;
        margin-left: 10rpx;
    }

</style>
